#include<iostream>
#include<string>

// zdl:: 这道题目直接使用包搜就可以解决、现在还是不是
using namespace std;
const int N = 25;
string a[N];
int cnt[N];
int n, ret;
void dfs(string path)
{
    if (ret < path.size()) ret = path.size();

    for (int i = 1; i <= n; i++)
    {
        if (cnt[i] > 1) continue;
        int cur1 = path.size() - 1, cur2 = 0;
        // zdl:: 这里需要注意需要及时处理包含额情况！！！
        while (cur1` >= 1 && cur2 < path.size() - 1)
        {
            if (path.substr(cur1) == a[i].substr(0, cur2 + 1))
            {
                cnt[i]++;
                dfs(path + a[i].substr(cur2 + 1));
                cnt[i]--;
            }
            cur1--;
            cur2++;
        }
    }
}
int main()
{
    cin>> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    char ch; cin >> ch;
    for (int i = 1; i <= n; i++)
    {
        if (a[i][0] == ch)
        {
            cnt[i]++;
            dfs(a[i]);
            cnt[i]--;
        }
    }


    cout << ret << endl;
    return 0;
}